<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
<c:choose>
	<c:when test="${bean.cmd == 'add' }">
	   <spring:message  code="pim"/> - <spring:message  code="add.employee"/>
	</c:when>
	<c:otherwise>
	   <spring:message  code="pim"/> - <spring:message  code="edit.employee"/> - <c:out value="${employee.visa}"></c:out>
	</c:otherwise>
</c:choose>
</title>
<link href="<%= request.getContextPath() %>/css/custom.css" rel="stylesheet" type="text/css" />
<link href="<%= request.getContextPath() %>/css/style.css" rel="stylesheet" type="text/css" />
<link href="<%= request.getContextPath() %>/css/v.css" rel="stylesheet" type="text/css" />
<link href="<%= request.getContextPath() %>/css/jquery.ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.6.2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-ui-1.8.14.custom.js"></script>
<%@include file="script/pim-util.jsp" %>
<%@include file="script/employee-script.jsp" %>
<style type="text/css">
.v-input,.v-select{
width: 200px;
}
.td-right{
padding-left: 50px;
padding-right: 30px;
}
.td-left{
padding-left: 30px;
}
</style>
</head>
<body>
<% try{ %>
<c:if test="${(bean.isSigned && bean.isAdmin) || (bean.cmd =='edit' && bean.visa == employee.visa)}">
<div id="all">
<div id="wrapper">
<div id="mainheader">
	<jsp:include page="include/common/headerSignedIn.jsp" />
</div> 
<div id="content-wrapper">
<div id="top-menu">
    <jsp:include page="include/common/topMenuHome.jsp" /> 
</div>
<div class="main-content">
<form:form action="" method="post" commandName="employee" acceptCharset="UTF-8" enctype="multipart/form-data">	   		  
<div>	
	<div class="v-row v-border-bottom" style="padding-top: 10px;">
		<div class="v-row-left" style="margin-left: 10px;">
			<span class="v-title">
				<c:choose>
					<c:when test="${bean.cmd == 'add' }">
					   <spring:message  code="add.employee"/>
					</c:when>
					<c:otherwise>
					   <spring:message  code="edit.employee"/>
					</c:otherwise>
				</c:choose>
			</span>
		</div>	
	</div>	
	<div class="v-body">
	<div class="v-row" id="v-global-message">
	   <c:if test="${addOK == true }">
	      	<span class="v-global-success-message v-row">
	      	    <span><spring:message  code="handle.add.employee.success" /></span>
	      	</span>
	   </c:if>
	   <c:if test="${addOK == false }">
	      	<span class="v-global-error-message v-row">
	      	    <span><spring:message  code="handle.add.employee.error" /></span>
	      	</span>
	    </c:if>
	    <c:if test="${editOK == true }">
	      	<span class="v-global-success-message v-row">
	      	    <span><spring:message  code="handle.edit.employee.success" /></span>
	      	</span>
	   </c:if>
	   <c:if test="${editOK == false }">
	      	<span class="v-global-error-message v-row">
	      	    <span><spring:message  code="handle.edit.employee.error" /></span>
	      	</span>
	    </c:if>
	    
	    <spring:hasBindErrors name="employee">
	        <c:if test="${errors.errorCount > 0}" >                     
	            <ul>
	               <c:forEach var="error" items="${errors.allErrors}">
	                  <li class="v-error-message">
	                     <spring:message code="${error.code}" text="${error.defaultMessage}"/>
	                  </li>
	               </c:forEach>
	            </ul>           
	        </c:if>
        </spring:hasBindErrors>	
    
	</div>	
	<div style="margin-left: 20px;">
		<div class="v-row">
			<div class="v-row-left">
				<span class="v-required-title">
				    <spring:message code="title.required.field" />
				</span>
			</div>
		</div>	
		
		<div class="v-row" style="padding: 10px;">  
		  <table>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.required.employee.firstname" /></span></td>             
		        <td class="td-left"><span><form:input path="firstname" maxlength="10" cssClass="v-input"/></span></td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.required.employee.lastname" /></span></td>        
		        <td><span><form:input path="lastname" maxlength="50" cssClass="v-input"/></span></td>    
		    </tr>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.required.employee.visa" /></span></td>             
		        <td class="td-left"><span><form:input path="visa" maxlength="10" cssClass="v-input"/></span></td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.required.employee.dateofbirth" /></span></td>        
		        <td><span><form:input path="dateofbirth" maxlength="20" cssClass="v-input"/></span></td>    
		    </tr>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.required.employee.diploma" /></span></td>             
		        <td class="td-left">
			        <span>
			              <form:select path="diploma.diplomaid" cssClass="v-select"> 
		                        <form:option value="0"><spring:message code="please.choice" /></form:option>                        
		                        <form:options items="${bean.diplomas}" itemLabel="name" itemValue="diplomaid"/>                       
		                  </form:select>
		            </span>
	            </td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.required.employee.department" /></span></td>        
		        <td>
		           <span>
	                     <form:select path="department.departmentid" cssClass="v-select"> 
	                        <form:option value="0"><spring:message code="please.choice" /></form:option>                        
	                        <form:options items="${bean.departments}" itemLabel="name" itemValue="departmentid"/>                       
	                     </form:select>				    
					</span>
		        </td>    
		    </tr>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.required.employee.rank" /></span></td>             
		        <td class="td-left">
			        <span>
	                     <form:select path="rank.rankid" cssClass="v-select">  
	                        <form:option value="0"><spring:message code="please.choice" /></form:option>                       
	                        <form:options items="${bean.ranks}" itemLabel="name" itemValue="rankid"/>                       
	                     </form:select>				    
					 </span>
	            </td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.required.employee.university" /></span></td>        
		        <td>
		           <span>
	                     <form:select path="university.universityid" cssClass="v-select">  
	                        <form:option value="0"><spring:message code="please.choice" /></form:option>                      
	                        <form:options items="${bean.universities}" itemLabel="name" itemValue="universityid"/>                       
	                     </form:select>				    
				   </span>
		        </td>    
		    </tr>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.employee.marriedstatus" /></span></td>             
		        <td class="td-left">
			        <span>
	                     <form:select path="marriedstatus" cssClass="v-select">                        
	                        <form:option value=""><spring:message code="please.choice" /></form:option>
	                        <form:option value="single"><spring:message code="marriedstatus.single" /></form:option>
	                        <form:option value="married"><spring:message code="marriedstatus.married" /></form:option>                      
	                     </form:select>				    
					 </span>
	            </td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.employee.gender" /></span></td>        
		        <td>
		           <span>
	                     <form:select path="gender" cssClass="v-select">                        
	                        <form:option value=""><spring:message code="please.choice" /></form:option>
	                        <form:option value="1"><spring:message code="gender.male" /></form:option>
	                        <form:option value="0"><spring:message code="gender.female" /></form:option>
	                     </form:select>				    
					 </span>
		        </td>    
		    </tr>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.employee.hireddate" /></span></td>             
		        <td class="td-left"><span><form:input path="hireddate" maxlength="20" cssClass="v-input"/></span></td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.employee.phone" /></span></td>        
		        <td><span><form:input path="phone" maxlength="20" cssClass="v-input"/></span></td>    
		    </tr>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.required.employee.email" /></span></td>             
		        <td class="td-left"><span><form:input path="email" maxlength="50" cssClass="v-input"/></span></td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.employee.bankaccountno" /></span></td>        
		        <td><span><form:input path="bankaccountno" maxlength="20" cssClass="v-input"/></span></td>    
		    </tr>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.employee.socialSecurityNo" /></span></td>             
		        <td class="td-left"><span><form:input path="socialSecurityNo" maxlength="20" cssClass="v-input"/></span></td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.employee.salary" /></span></td>        
		        <td><span><form:input path="salary" maxlength="10" cssClass="v-input"/></span></td>    
		    </tr>
		    <tr>
		        <td style="color:black;"><span><spring:message code="title.employee.languages" /></span></td>             
		        <td class="td-left"><span><form:input path="languages" maxlength="100" cssClass="v-input"/></span></td>      
		        <td style="color:black;" class="td-right"><span><spring:message code="title.required.employee.status" /></span></td>        
		        <td>		      
		         <span>														
	                <form:radiobutton path="status" value="1" id="enable" />
	                <label for="enable"><spring:message code="status.enable"/></label>
	              </span>	              
	              <span>                    
	                <form:radiobutton path="status" value="0" id="disable" />
	                <label for="disable"><spring:message code="status.disable" /></label> 
	              </span> 		      
		        </td>    
		    </tr>
		    <tr>
		      <td style="color:black;"><span><spring:message code="title.employee.placeofbirth" /></span></td>
		      <td class="td-left" colspan="3"><span><form:input path="placeofbirth" cssStyle="height: 20px; width: 380px;" maxlength="200" cssClass="v-input"/></span></td>
		    </tr>		  
		    <tr>
		      <td style="color:black;"><span><spring:message code="title.required.employee.address" /></span></td>
		      <td class="td-left" colspan="3"><span><form:input path="address" cssStyle="height: 20px; width: 380px;" maxlength="200" cssClass="v-input"/></span></td>
		    </tr>
		    <tr>
		      <td style="color:black;"><span><spring:message code="title.employee.imageurl" /></span></td>
		      <td class="td-left" colspan="3">
		        <span><input class="v-input" type="file" id="imageurl" name="imageurl" maxlength="200" onchange="imagePreview('imageurl', 'image-preview')" size="46"/></span>
			  </td>
		    </tr>
		    <tr>
		      <td>
		          <div class="new-manage-org-logo-org" style="border: thin ridge #E0EDF4;">	
				   <c:choose>
				   <c:when test="${addOK == true || bean.cmd == 'edit' }">					      				      				      			    
					  <c:set var="smallImageUrl" value="${employee.imageurl}" />
					  <c:choose>
							<c:when test="${smallImageUrl == null || smallImageUrl == '' }">
								<img id="image-preview"  alt="" src="<%=request.getContextPath()%>/images/small_noImage.gif" 
								     onLoad='scaleImg(this, 80, 80)' />
							</c:when>							
							<c:otherwise>
								<img id="image-preview" alt="" src='<c:out value="${smallImageUrl}"></c:out>' 
								     onLoad='scaleImg(this, 80, 80)'>
							</c:otherwise>
					  </c:choose>					 			  
				   </c:when>
				   <c:otherwise>
				        <img id="image-preview"  alt="" src="<%=request.getContextPath()%>/images/small_noImage.gif" 
						     onLoad='scaleImg(this, 80, 80)' />
				   </c:otherwise>
				   </c:choose>					
				</div>		
		      </td>
		      <td class="td-left" colspan="3"><span class="v-info"><spring:message code="warning.employee.logo" /></span></td>
		    </tr>
		  </table>
		</div>																							
																		
		<div class="v-row">
		    <br/>
			<div class="v-row-center">
				<span><input type="submit" class="bt-form" value="<spring:message code="button.save" />" /></span>
				<span>
				     <input type="button" class="bt-form" onclick="cancel('<c:out value='${bean.returnToFullPageURL }'/>')" value="<spring:message code="button.cancel"/>" />
				</span>
			</div>
		</div>
		
	</div>
</div>
</div>
<input type="hidden" name="cmd" value="${bean.cmd}"/>
<input type="hidden" name="returnToFullPageURL" value="${bean.returnToFullPageURL}"/>
</form:form>	 	
</div>	
</div>
</div>
<div class="footer">
	<jsp:include page="include/common/footer.jsp" />
</div>
</div>			   
</c:if>
<% } catch(RuntimeException re){ re.printStackTrace(); } %>
</body>
</html>	